//eslint disable next line
<template>
  <el-form @submit.native.prevent="saveArticle" ref="form" :model="article" label-width="80px">
    <el-form-item label="文章标题">
      <el-input v-model="article.title"></el-input>
    </el-form-item>

    <el-form-item label="文章内容">
      <el-input type="textarea" v-model="article.body"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" native-type="submit">保存</el-button>
      <el-button>取消</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  data() {
    return {
      article: {}
    };
  },
  methods: {
    saveArticle() {
      this.$http.put(`articles/${this.$router.params.id}`, this.article).then(res => {
        this.$message({
          message: "文章更新成功！",
          type: "success"
        });
        //提交完成后，跳转到文章列表页
        this.$router.push('/article/index')
      });
    },
    fetch(){
      this.$http.get(`articles/${this.$router.params.id}`).then(res=>{
        this.article = res.data
      })
      
    }
  },
  create(){
    this.fetch();
  }
};
</script>